extends IEffectBehavior


class_name ComplexEffectBehavior


## 运行模式
enum DoMode {
    ## 运行索引项
    Index,
    ## 随机触发一项
    Random,
    ## 循环触发
    Wrap,
    ## 运行全部
    All,
}


## 子效果的执行方式
@export var mode: DoMode = DoMode.Index
## 挂载的事件类型
@export var events: Array[CharacterComponent.Event] = []
## 挂载的效果
@export var effects: Array[EffectValue] = []


func support() -> Array:
    return events

func do_event(character: CharacterComponent, v: EffectValue, e: CharacterEvent) -> void:
    var count: int = effects.size()
    if count < 1:
        return
    match mode:
        DoMode.Index:
            var effect: EffectValue = effects[clampi(v.value - 1, 0, count - 1)]
            effect.behavior.do_event(character, effect, e)
        DoMode.Random:
            var effect: EffectValue = effects.pick_random()
            effect.behavior.do_event(character, effect, e)
        DoMode.Wrap:
            v.value = wrapi(v.value + 1, 0, count - 1)
            var effect: EffectValue = effects[v.value]
            effect.behavior.do_event(character, effect, e)
        DoMode.All:
            for effect in effects:
                effect.behavior.do_event(character, effect, e)
